import App from './App'

// 在入口中执行 utils/utils.js
import './utils/utils'

// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
Vue.config.productionTip = false

App.mpType = 'app'
const app = new Vue({
  ...App,
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
import { createPinia } from 'pinia'
// import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import { createPersistedState } from 'pinia-plugin-persistedstate'

export function createApp() {
  const app = createSSRApp(App)
  const pinia = createPinia()
  // pinia.use(piniaPluginPersistedstate)
  // 自定义pinia实例
  pinia.use(
    createPersistedState({
      key: (id) => `__persisted__${id}`,
      storage: {
        setItem(key, value) {
          uni.setStorageSync(key, value)
        },
        getItem(key) {
          return uni.getStorageSync(key)
        },
      },
    })
  )
  app.use(pinia)
  return {
    app,
  }
}
// #endif
